package com.tz.dao;

import com.tz.entity.Account;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by user on 2016/10/10.
 */
@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired
    private SessionFactory sf;

    private Session getSession(){

        return sf.getCurrentSession();
    }


    @Override
    @Transactional
    public void save(Account account) {
        getSession().save(account);
    }

    @Override
    @Transactional
    public void update(Account account) {
        getSession().update(account);
    }

    @Override
    @Transactional
    public Account get(int id) {
        return (Account) getSession().get(Account.class,id);
    }
}
